#!/bin/bash
# 设置代理环境变量脚本
# 使用方法: source setup_proxy.sh 或 . setup_proxy.sh

# 根据你的代理设置修改这里（默认是 127.0.0.1:1087）
PROXY_HOST="127.0.0.1"
PROXY_PORT="1087"

# 设置代理
export http_proxy="http://${PROXY_HOST}:${PROXY_PORT}"
export https_proxy="http://${PROXY_HOST}:${PROXY_PORT}"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"

echo "✅ 代理已设置："
echo "   HTTP 代理:  $http_proxy"
echo "   HTTPS 代理: $https_proxy"
echo ""
echo "💡 提示：这些设置只在当前终端会话有效"
echo "💡 要永久设置，请将以下内容添加到 ~/.zshrc 或 ~/.bash_profile："
echo ""
echo "   export http_proxy=\"http://${PROXY_HOST}:${PROXY_PORT}\""
echo "   export https_proxy=\"http://${PROXY_HOST}:${PROXY_PORT}\""
echo ""
echo "🧪 测试代理连接..."
if curl -I https://www.google.com --max-time 5 --proxy "$http_proxy" > /dev/null 2>&1; then
    echo "✅ 代理连接正常！"
else
    echo "⚠️  代理连接失败，请检查："
    echo "   1. 代理服务是否运行"
    echo "   2. 代理地址和端口是否正确（当前: ${PROXY_HOST}:${PROXY_PORT}）"
    echo "   3. 代理是否需要认证"
fi

